using System;
using System.IO;
using System.Reflection;
using System.Web.Hosting;
using EPiServer.Web.Hosting;

namespace EPiSugar.UnitTesting
{
    public class FakeHostingEnvironment : IHostingEnvironment
    {
        // Methods
        public string MapPath(string virtualPath)
        {
            return Path.Combine(Environment.CurrentDirectory, virtualPath.Trim('/', '~').Replace('/', '\\'));
        }

        public void RegisterVirtualPathProvider(VirtualPathProvider virtualPathProvider)
        {
            typeof(VirtualPathProvider).GetField("_previous", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(virtualPathProvider, VirtualPathProvider);
            VirtualPathProvider = virtualPathProvider;
        }

        public string ApplicationID { get; set;}
        public string ApplicationPhysicalPath { get; set;}
        public string ApplicationVirtualPath { get; set;}
        public VirtualPathProvider VirtualPathProvider { get; set;}
    }
}